package com.netease.nim.uikit.session.actions;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import com.netease.nim.uikit.session.constant.RequestCode;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： LoginPresenter
 * @包名称： com.doudoukeji.service.Activity.Login
 * @创建人： zhanjunjie
 * @创建时间：2016/3/14 15:06
 * @修改人：
 * @修改时间：2016/3/14 15:06
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class ImageBasePresenter {

    private ImageBaseView imagebaseview;
    private Context context;
    private MyBroadcastReceiver mMyBroadcastReceiver;
    public ImageBasePresenter(Context context) {
        this.context = context;
    }
    public void getIntent(ImageBaseView view){
        this.imagebaseview = view;
    }

    /**
     * 初始化广播
     */
    public void initBroadcast() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("W_Y_Y_X_Doctor");
        mMyBroadcastReceiver = new MyBroadcastReceiver();
        //消息红点
        context.registerReceiver(mMyBroadcastReceiver, intentFilter);
    }

    private class MyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("W_Y_Y_X_Doctor")) {
                boolean end = intent.getBooleanExtra("End", false);
                int requestCode = intent.getIntExtra("requestCode", 0);
                Bundle bl = intent.getExtras();
                Intent data = (Intent) bl.get("data");
                if (end){
                    context.unregisterReceiver(mMyBroadcastReceiver);
                    return;
                }
                switch (requestCode) {
                    case RequestCode.PICK_IMAGE:
                        imagebaseview.getLocalPicture(requestCode,data);
//                        onPickImageActivityResult(requestCode, data);
                        break;
                    case RequestCode.PREVIEW_IMAGE_FROM_CAMERA:
//                        onPreviewImageActivityResult(requestCode, data);
                        imagebaseview.getPackPicture(requestCode,data);
                        break;
                }
            }
        }
    }

}
